package src.unapec.security.UI.EntornoJava;

import java.awt.Color;
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;
import javax.swing.SwingConstants;

import src.unapec.security.models.EntornoJava.AIOOBE;

public class AIOOBEV extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JSpinner jSpinner = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel4 = null;
	
	private AIOOBE aioobe = new AIOOBE();

	private SpinnerListModel spinnerListModel = null;  //  @jve:decl-index=0:

	private JLabel jLabel5 = null;
		
	/**
	 * This is the default constructor
	 */
	public AIOOBEV() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(421, 104);
		this.setContentPane(getJContentPane());
		this.setTitle("ArrayIndexOutOfBoundsException");
		this.jLabel1.setText(String.valueOf(aioobe.getSize())+" / 0..4");
		fillSpinnerModel();
		this.jSpinner.setModel(spinnerListModel);
		
		
	}

	private void fillSpinnerModel(){
		
		Object[] values = new Object[15];
		int index = 0;
		
		for (int i = -5; i < 10; i++) {
			
			values[index] = String.valueOf(i);
			index++;
			
		}
		
		spinnerListModel = new SpinnerListModel(values);
		
		
	}
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel5 = new JLabel();
			jLabel5.setBounds(new Rectangle(309, 14, 97, 28));
			jLabel5.setIcon(new ImageIcon(getClass().getResource("/src/unapec/security/Utils/images/remove-32x32.png")));
			jLabel5.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel5.setText("");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(180, 47, 229, 15));
			jLabel4.setForeground(new Color(51, 51, 204));
			jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel4.setText("ArrayIndexOutOfBoundsException");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(124, 46, 45, 19));
			jLabel3.setText("Value:");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(13, 25, 49, 26));
			jLabel2.setText("Index:");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(218, 13, 81, 27));
			jLabel1.setText("getSize();");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(123, 13, 91, 26));
			jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
			jLabel.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel.setText("Array Length:");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(getJSpinner(), null);
			jContentPane.add(jLabel3, null);
			jContentPane.add(jLabel4, null);
			jContentPane.add(jLabel5, null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jSpinner	
	 * 	
	 * @return javax.swing.JSpinner	
	 */
	private JSpinner getJSpinner() {
		if (jSpinner == null) {
			jSpinner = new JSpinner();
			jSpinner.setBounds(new Rectangle(66, 12, 43, 55));
			jSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
				public void stateChanged(javax.swing.event.ChangeEvent e) {
					
					try{
					
					int index = new Integer(getJSpinner().getValue().toString()).intValue();
					jLabel4.setText(String.valueOf(aioobe.getValue(index)));
					jLabel5.setIcon(new ImageIcon(getClass().getResource("/src/unapec/security/Utils/images/accept-32x32.png")));
					
					}catch(ArrayIndexOutOfBoundsException aioobe){
						
						jLabel4.setText("ArrayIndexOutOfBoundsException");
						jLabel5.setIcon(new ImageIcon(getClass().getResource("/src/unapec/security/Utils/images/remove-32x32.png")));
						
					}
					
				}
			});
		}
		return jSpinner;
	}

	/**
	 * This method initializes spinnerListModel	
	 * 	
	 * @return javax.swing.SpinnerListModel	
	 */
	private SpinnerListModel getSpinnerListModel() {
		if (spinnerListModel == null) {
			spinnerListModel = new SpinnerListModel();
		}
		return spinnerListModel;
	}
	
	public static void main(String[] args) {
		
		AIOOBEV visual = new AIOOBEV();
		visual.setVisible(true);
		visual.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
	

}  //  @jve:decl-index=0:visual-constraint="10,10"
